# !/usr/bin/python3
# -*- coding: utf-8 -*-
# ------------------------------------------
# @Time    : Date - 2021/9/24   Time - 19:48
# @Author  : Spence Guo Tang
# @FileName: _t2.py
# ------------------------------------------

import sys
from typing import List


def oct_to_bin(nums: List[int]) -> List[str]:
    result, temp = [], []
    max_length = 0
    for x in nums:
        y = str(bin(x).replace("0b", ""))
        temp.append(y)
        max_length = max(max_length, len(y))
    for z in temp:
        if len(z) < max_length:
            z = ''.join(["0"]*(max_length-len(z))) + z
        result.append(z)
    return result


def min_operation_count(nums: List[str]) -> int:
    counts = 0
    length = len(nums[0])
    for i in range(length):
        source_1 = int(nums[0][i])
        source_2 = int(nums[1][i])
        target = int(nums[2][i])
        if (source_1 or source_2) != target:
            if target == 1:
                counts += 1
            else:
                if source_1 == 1 and source_2 == 1:
                    counts += 2
                else:
                    counts += 1
    return counts


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    samples = []

    for _ in range(n):
        line = list(map(int, sys.stdin.readline().strip().split(" ")))
        samples.append(line)

    for i in range(len(samples)):
        bin_nums = oct_to_bin(samples[i])
        print(min_operation_count(bin_nums))
